{	Problem: http://codeforces.ru/problemset/problem/74/C
	Verdict: Accepted
}
var a,b:int64;
begin
read(a,b);
dec(a); 
dec(b);
while a*b>0 do
    if a>b then a:=a mod b else b:=b mod a;
write(a+b+1);
end.